package com.lemons.hackaton.app.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FindUtils {

	private static final String REGEX2 = "\\bUSD\\d+\\b";

	public static String findPersonInText(String text, List<String> pDictionary) {
		for (int j = 0; j < pDictionary.size(); j++) {
//			System.out.println("Searching... " + pDictionary.get(j));
			Pattern activityPatter = Pattern.compile("\\s\\b" + pDictionary.get(j) + "\\s\\b");
			Matcher regexMatcher = activityPatter.matcher(text);
			if(regexMatcher.find()){
				//System.out.println("Founded " + pDictionary.get(j));
				return pDictionary.get(j);
			}
		}
		return null;
	}

	public static String findMoneyInText(String text) {
		Pattern p1 = Pattern.compile(REGEX2);
		Matcher regexMatcher = p1.matcher(text);
		while (regexMatcher.find()) {
			return regexMatcher.group();
		}
		return "0";
	}

	public static List<String> findActivitiesInText(String text, List<String> aDictionary) {
		List<String> activities = new ArrayList<String>();
		
		for (int j = 0; j < aDictionary.size(); j++) {
			Pattern activityPatter = Pattern.compile("\\s\\b" + aDictionary.get(j) + "\\s\\b");
			Matcher regexMatcher = activityPatter.matcher(text);
//			System.out.println("Searching... " + aDictionary.get(j));
			if(regexMatcher.find()){
				//System.out.println("Founded... " + aDictionary.get(j));
				activities.add(aDictionary.get(j));
			}
			
			/*if (text.contains(aDictionary.get(j))) {
				activities.add(aDictionary.get(j));
			}*/
		}
		return activities;
	}
}
